local skel = fk.CreateSkill {
  name = "efengqi__wushuang",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["efengqi__wushuang"] = "无双",
  [":efengqi__wushuang"] = "锁定技，当你使用【杀】时，需增加至多两个目标，每少增加一个，响应所需【闪】+1。你打出【杀】时获得之。",

  ["#efengqi__wushuang-choose"] = "无双：为你使用的%arg增加至多两个目标",

  ["$efengqi__wushuang1"] = "别再做无谓的挣扎了！",
  ["$efengqi__wushuang2"] = "无敌还真是寂寞啊。",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) or target ~= player or data.card.trueName ~= "slash" then return false end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 2
    local targets = data:getExtraTargets()
    if #targets > 0 then
      local tos = room:askToChoosePlayers(player, {
        min_num = 1, max_num = num, skill_name = skel.name, targets = targets, cancelable = true,
        prompt =  "#efengqi__wushuang-choose:::"..data.card:toLogString()
      })
      if #tos > 0 then
        for _, to in ipairs(tos) do
          data:addTarget(to)
        end
        num = num - #tos
      end
    end
    if num > 0 then
      data.extra_data = data.extra_data or {}
      data.extra_data.efengqi__wushuangNum = num
    end
  end,
})

skel:addEffect(fk.CardResponding, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) or target ~= player or data.card.trueName ~= "slash" then return false end
    return table.find(Card:getIdList(data.card), function (id)
      return player.room:getCardArea(id) == Card.Processing
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(Card:getIdList(data.card), function (id)
      return room:getCardArea(id) == Card.Processing
    end)
    room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
  end,
})

skel:addEffect(fk.TargetSpecified, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.extra_data and data.extra_data.efengqi__wushuangNum
  end,
  on_refresh = function (self, event, target, player, data)
    data:setResponseTimes(data:getResponseTimes(data.to) + data.extra_data.efengqi__wushuangNum, data.to)
  end,
})

return skel
